package com.iot.ruler.core;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author lzb
 * @Date 2023/2/23 13:28
 */
public class RulerThreadFactory implements ThreadFactory {

    private final AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public Thread newThread(Runnable r) {
        String name = "ruler-" + atomicInteger.incrementAndGet();
        System.out.println("创建新的线程：" + name);
        Thread thread = new Thread(r);
        thread.setName(name);
        return thread;
    }

}
